﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;

namespace WebsiteAdmin.Salomon.ProInfo
{
    public partial class CatList : System.Web.UI.Page
    {
        public int strCatID = 0;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["pid"] != null && Request["pid"].ToString() != "")
                    strCatID = Convert.ToInt32(Request["pid"]);

                DataTable dtCat = Bll.Category.MULTIPLE(Global.ConSalomon, strCatID);

                if (dtCat.Rows.Count > 0)
                {
                    RP_Cat.DataSource = dtCat.DefaultView;
                    RP_Cat.DataBind();
                }

                dtCat.Dispose();
            }
            else
            {
                Response.Redirect("/Trace.aspx?Err=1");
            }
        }

        protected void RP_Cat_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                // 找到分类Repeater关联的数据项
                DataRowView rowv = (DataRowView)e.Item.DataItem;

                Label lblParCatName = ((Label)e.Item.FindControl("ParCatName"));
                Label lblViewPar = ((Label)e.Item.FindControl("ViewPar"));
                if (Convert.ToInt32(rowv["ParID"]) == 0)
                {
                    lblParCatName.Text = "一级分类";
                    lblViewPar.Text = "--";

                }
                else
                {
                    lblParCatName.Text = rowv["ParCatName"].ToString();
                    if ((Convert.ToInt32(rowv["GraID"]) == 0))
                        lblViewPar.Text = "<a href=\"CatList.aspx\" >上级</a>";
                    else
                        lblViewPar.Text = "<a href=\"CatList.aspx?pid=" + rowv["GraID"].ToString() + "\" >上级</a>";                    
                }


                Label lblAddCat = ((Label)e.Item.FindControl("AddCat"));
                if ((Convert.ToInt32(rowv["CatRank"]) < 3))
                    lblAddCat.Text = "<a href=\"/ProInfo/CatCreate.aspx?pid=" + rowv["PKID"] + "\">添加子类</a>";
                else
                    lblAddCat.Text = "--";

                Label lblDelLink = ((Label)e.Item.FindControl("DelLink"));
                Label lblViewCat = ((Label)e.Item.FindControl("ViewCat"));
                if (Convert.ToInt32(rowv["Num"]) == 0)
                {
                    lblDelLink.Text = "<a href=\"javascript:void(0);\" onclick=\"javascript:Del(" + rowv["PKID"] + ",'" + rowv["CatName"] + "');\">删除</a>";
                    lblViewCat.Text = "--";

                }
                else
                {
                    lblDelLink.Text = "--";
                    lblViewCat.Text = "<a href=\"CatList.aspx?pid=" + rowv["PKID"].ToString() + "\" >子级</a>";
                }

                //ViewPar

                
            }
        }

    }
}
